<template>
  <div class="login">
    <img src="@/assets/images/pc.png" class="pc"/>
    <label>
      幻美确认登录
    </label>
     <label>
      请确认是本人操作
    </label>
    <label>并确保二维码来源安全 </label>
    <div class="btn">
      <button  @click="complateLogin">确认登录</button>
      <button  @click="cancel">取消</button>
    </div>
  </div>

</template>

<script>
import { postCode } from '@/apis/mine'
import {Toast} from 'vant'
export default {
  name: '',
  data () {
    return {
      codeResult: ''
    }
  },
  created () {
  },
  methods: {
    cancel () {
      this.close()
    },
    complateLogin () {
      let ua = navigator.userAgent
      let param = {}
      let that = this;
      if (ua.indexOf('web_ua') > -1) {
        
        let uaData = JSON.parse(ua.match(/web_ua=(\S*)/)[1])
        param = {
            token: uaData.token,
            qrcode: uaData.qrcode
        }
      } else if(ua.indexOf('ios_app')>-1&&ua.indexOf('token')>-1){
        
       
         var ios_data = JSON.parse(ua.match(/ios_app=([\S\s]*)/)[1]);
        param = {
            token: ios_data.token,
            qrcode:ios_data.qrcode
        }
      }
      postCode(param).then(res=>{
        if(res.data.code==200){
          that.close()
        } else {
           Toast(res.data.message);
        }
      })
      
    },
    close () {
       if (this.$systemInfo() === "android") {
        window.android.closeCurrentPage();
      } else if (this.$systemInfo() === "ios") {
        localStorage.clear();
        window.webkit.messageHandlers.closeCurrentPage.postMessage(null);
      }
    }
  }
}
</script>

<style scoped>
   .login{ color: #ffffff;display: flex;justify-content: center;align-items: center;flex-direction: column;height: 100vh;}
   .login label{display: block; text-align: center;}
   .login label:nth-child(2){font-size: 0.34rem;  margin-top: 0.97rem;}
   .login label:nth-child(3){font-size: 0.28rem;color: #999999 !important; margin-top: 0.2rem;}
   .login label:nth-child(4){font-size: 0.28rem;color: #999999 !important;}
   .pc{display: block;width: 1.76rem;height: 1.66rem;margin: 0 auto;}
   .btn{width: 100%;}
   .btn button{width: 80%;height: 0.86rem;display: block;margin: 0 auto;font-size: 0.36rem;}
   .btn button:nth-child(1){background: #FD0000;border: none;margin-top: 2.93rem;}
   .btn button:nth-child(2){background: none;border: none;}
</style>
